<?php
session_start();
include_once('inc/connection.php');
 include('functions.php');

$user = $_POST['user'];
$pass = $_POST['pass'];

//---------------------------
 try{
       $conn = new Mongo('mongodb-env-ecom.whelastic.net', array("username" => 'admin', "password" => 'Yar66WQObe'));

 
 $db = $conn->test;
   if ($conn){
     //echo "<center><h1>Good connection</h1></center>";
     	$db = $conn->mongodbconnection;
     $collection = $db->login;
     //$cursor = $collection->find();
	$cursor = $collection->find();

// iterate through the results
foreach ($cursor as $document) {
  //echo $document['user_id'] . "\n";
  if ($user == $document['uname'] && $pass == $document['pass']) {

        $_SESSION['id'] = $document['id'];
        $_SESSION['name'] = $document['first'];
        $_SESSION['lname'] = $document['last'];
    //$_SESSION['role'] = $document['role'];
        $_SESSION['lang'] = 'en';
		$_SESSION['cart']= array();
		$_SESSION['temp']= array();
		
		//-----------------------------------------------
		
		userVisit();
			
		//----------------------------------------------

    } else {
//        echo 'la3d  ' . $user . '  ' . $pass . '  ';
    }

}

     

   }
 
 }catch( Exception $e){
 
       echo  "<center><h1>Doesn't work</h1></center>";
 
       exit;
 
 
} 

//--------------------------

$sql = "SELECT * FROM `users`";
//            $result = mysql_query("SELECT * FROM product");
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
    if ($user == $row['uname'] && $pass == $row['pass']) {
//        echo 'da5al  ' . $user . '  ' . $pass . '  ';
        $_SESSION['id'] = $row['id'];
      //$_SESSION['name'] = $row['first'];
      //$_SESSION['lname'] = $row['last'];
        $_SESSION['role'] = $row['role'];
      //$_SESSION['lang'] = 'en';
      //	$_SESSION['cart']= array();
      //	$_SESSION['temp']= array();
		
		//-----------------------------------------------
		
      //		userVisit();
			
		//----------------------------------------------

    } else {
//        echo 'la3d  ' . $user . '  ' . $pass . '  ';
    }
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <meta name="Hasan" content="EC" />
        
        <link rel="shortcut icon" href="tsc.ico" />
        <link href="css/en/mycss.css" rel="Stylesheet" type="text/css" />
        <link href="css/en/header.css" rel="Stylesheet" type="text/css" />
        <link href="css/en/login.css" rel="Stylesheet" type="text/css" />

        <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
        <script src="js/header.js"></script>
        <title></title>
    </head>

    <body>

<!--        <form action="../inc/login.php"  method="post" enctype="multipart/form-data">
            <div id="loginArea">
                <ul>
                    <li>
                        <div id="loginTitle">
                            <?php
                            if (isset($_SESSION['name']))
                                echo '<a href="javascript:void(0)"><p style="font-size: 12px; color: lightblue;"> ' . $_SESSION['name'] . '</p></a>';
                            else
                                echo '<a href="javascript:void(0)"><p style="font-size: 12px; color: lightblue;">Login/Register</p></a>';
                            ?>
                        </div>
                    </li>
                    <li>
                        <div id="loginFields">
                             <p style="float: left;font-size: 12px; color: white;">user name</p> 
                            <?php
                            if (isset($_SESSION['name']))
                                echo '<div id="loggedInDiv">
                            <a href="logout.php" > تسجيل خروج</a>
                            <a href="../companyAddProduct.php" >صفحة الإدارة</a>
                            </div>';
                            else
                                echo '<input style="margin-right: 5px;float: right;" type="text" name="user" value="user name" class="grayClass" content="user name" />
                    <p style="float: left;font-size: 12px; margin-left: 10px; color: white;">password</p>
                    <input style="margin-right: 5px;float: right;" type="password" name="pass" value="password" content="password" class="grayClass"/>
                    <input id="login" type="submit" value="login"/>
                    <input id="register" type="button" value="Register"/>';
                            ?>
                        </div>
                    </li>
                </ul>
            </div>
        </form>

        <div id="header">
            <ul id="homeButtonUL">
                <a href="../index.php"><li class="homeButton" ><img src="../images/home.png" width="30px"/></li></a>
                <li class="headerLogo"><img src="../images/logo.png" width="80px"/></li>
            </ul>
            <ul id="cartButton">
                <a href="../products.php"><li class="cartNav"><img src="../images/cart.png" width="25px"/>
                        <p>البضائع</p>
                    </li></a>
            </ul>
            <ul id="headerNavLinksUL">
            </ul>
        </div>-->
        <?php
            include 'inc/header.php';
        ?>
        <div id="welcomeDiv">
            <div id="welcomeDivImg">
                <img src="images/slider.jpg" width="200px"/>
            </div>
            <a href="index.php">الرئيسية</a>
        </div>

    </body>
</html>
